// pages/repair/workBack/back.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    value: "",
    code: "",
    index: 0,
    humanList: [],
  },
  submit(e) {
    let { personId } = e.detail.value;
    let that = this
    if (personId) {
      let obj = {}
      obj.personId = personId
      obj.id = this.data.id
      wx.showModal({
        title: '提示',
        content: '是否确认转单',
        success(res) {
          if (res.confirm) {
            that.axios.custom("RepairWorkOrderHandle", "transfer", obj)
              .then((res) => {
                if (res.code == '200') {
                  wx.showToast({
                    title: '操作成功',
                    icon: 'success',
                    duration: 2000,
                    success: () => {
                      that.Router.push({
                        path: 'workLog',
                        query: {},
                        openType: 'reLaunch',
                        duration: 2000,
                      })
                    }
                  })

                }
              })
              .catch((res) => {
                console.log(res)
              });
            // 提交请求
            // 返回列表页
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    } else {
      wx.showModal({
        content: '请选择转单人员',
        showCancel: false,
      })
    }

  },
  personChange(e) {
    this.setData({
      index: e.detail.value
    })
  },
  // 获取下拉框的人员
  _getPerson() {
    let condition = {}
    condition.code = this.data.code
    //condition.code = '110553';
    this.axios
      .query('StaffEquip', {}, condition,)
      .then((res) => {
        // 处理数据
        if (res.code == '200') {
          let cache = []
          res.data.rows.forEach(item => {
            let obj = {}
            obj.text = item.name
            obj.value = item.id
            cache.push(obj)
          });
          this.setData({
            humanList: cache
          })
        }

      })
      .catch((e) => {
        console.log(e);
      });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.data.id = options.id;
    this.data.code = options.code;
    this._getPerson();
    console.log(options, '页面传值')
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})